package com.example.receiver;

import java.util.ArrayList;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.LatLng;

import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;

public class GetCurLocation implements LocationListener {

	private LocationManager m_lm;
	private Location m_loc;
	private Context m_con;

	// Global variable
	public double m_lat = 0;
	public double m_lot = 0;
	public double mlat = 0;
	public double mlng = 0;
	public GoogleMap Mapp;
	ArrayList<LatLng> mMarkerPointss;

	// public LatLng pointt;

	public GetCurLocation() {

	}

	public GetCurLocation(LocationManager lm, Context con, GoogleMap Map) {

		this.m_lm = lm;
		Log.d("this.m_lm", "" + this.m_lm);
		Log.d("lm", "" + lm);
		this.m_con = con;
		this.Mapp = Map;
		Log.d("this.myMap", "" + this.Mapp);
		Criteria cr = new Criteria();
		String pr = lm.getBestProvider(cr, true);
		m_loc = lm.getLastKnownLocation(pr);
		lm.requestLocationUpdates(pr, 20000, 0, this);
		getLatLot();

	}

	public void getLatLot() {
		if (m_loc != null) {
			onLocationChanged(m_loc);
		}
		m_lat = (double) m_loc.getLatitude();
		m_lot = (double) m_loc.getLongitude();
	}

	@Override
	public void onLocationChanged(Location location) {
		// TODO Auto-generated method stub

		GetData main = new GetData();
		mMarkerPointss = new ArrayList<LatLng>();
		mMarkerPointss = main.mMarkerPoints;
		// map = main.myMap;
		Log.d("mMarkerPoints", " " + mMarkerPointss);
		Log.d("mMarkerPoints1", " " + main.mMarkerPoints);

		if (mMarkerPointss.size() < 1) {
			mlat = m_loc.getLatitude();
			Log.d("mlat1", "" + mlat);
			mlng = m_loc.getLongitude();
			getMlat();
			getMlng();
			// pointt = new LatLng(mlat, mlng);
		}

	}

	@Override
	public void onProviderDisabled(String provider) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onProviderEnabled(String provider) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub

	}

	public double getMlat() {
		Log.d("mlat", "" + mlat);
		return mlat;
	}

	public double getMlng() {
		return mlng;
	}

}
